from scapy.all import ARP, Ether, srp

def discover_hosts(network_address):
    """Discover active hosts in the specified network"""
    active_hosts = []
    try:
        # Create ARP packet
        arp = ARP(pdst=network_address)
        # Create Ethernet packet
        ether = Ether(dst="ff:ff:ff:ff:ff:ff")
        # Combine packets
        packet = ether / arp
        # Send packets and receive responses
        result = srp(packet, timeout=3, verbose=False)[0]
        # Extract active hosts' IP addresses
        for sent, received in result:
            active_hosts.append(received.psrc)
    except Exception as e:
        print(f"Error: {e}")
    return active_hosts

def main():
    network_address = input("Enter the network address (e.g., 192.168.1.0/24): ")
    print("Discovering active hosts in the specified network...")
    active_hosts = discover_hosts(network_address)
    if active_hosts:
        print("Active hosts found:")
        for host in active_hosts:
            print(f"- {host}")
    else:
        print("No active hosts found.")

if __name__ == "__main__":
    main()
    
# pip install scapy
# sansjtw